
var array = []
var map = {}
list.forEach(item => {
    map[item.pid === rootValue] 
        array.push(item)
})

list.forEach(item => {
    if(map[item.pid]) {
      if(map[item.pid].children) {
          map[item.pid].children.push(item)
      }else {
          map[item.pid].children = [item]
      }
    }
})
return array